<template>
  <div class="auto">
    <validator name='v'>
      <form novalidate class="form-horizontal">
        <div  style="margin-top:10px" :class="[$v.f_tablebase.dctest ? 'has-error' : 'has-success']">
          <label for="f_tablebase"  class=" col-sm-2 control-label">表底数:</label>
          <div class="col-sm-3">
            <input class="form-control" type="number" v-model="model.f_tablebase"
             v-validate:f_tablebase='{dctest: [row.f_meter_base, ">=" ] }'  placeholder="表底数" :disabled="disabled">
             <span v-if="$v.f_tablebase.dctest" style="color:red ">本次表底数不能小于上次表底数</span>
          </div>
        </div>
      </form>
      <div class="col-sm-4" style="margin-left:8%" v-if="!message">
        <button class="btn btn-success" @click="confirm()"  :disabled='!$v.valid' id='comprehen-comOpe-chaMet-macMet-确认'>确&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;认</button>
        <button class="btn btn-default" @click="clean()" style="width:80px;margin-left:20px;" id='comprehen-comOpe-chaMet-macMet-取消'>取&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;消</button>
      </div>
    </validator>
  </div>
</template>
<script>
/**
*换表管理
*处理表类型为机表和物联网表的旧表信息
*/
import AppData from '../../../../../stores/AppData'
export default {
  data () {
    return {
      model: {},
      disabled: false
    }
  },
  props: ['row', 'message'],
  watch: {
    'row' (val) {
      this.model.f_user_id = val.f_user_id
      this.model.f_userinfo_id = val.f_userinfo_id
    }
  },
  ready () {
    this.model.f_user_id = this.row.f_user_id
    this.model.f_userinfo_id = this.row.f_userinfo_id
  },
  methods: {
    confirm () {
      this.model.lazy = AppData.getSingleValue('滞纳期限')
      if (this.model.f_tablebase > this.row.f_meter_base) {
        this.$ChangeMeterService.changeMeter(this.model, this.row).then((res) => {
          if (res.data.isAutoAcc === '是') {
            this.$dispatch('firstsuccess', 'nohand', null)
          } else {
            this.$dispatch('firstsuccess', 'hand', res.data.row)
            this.disabled = true
          }
        }).catch((error) => {
          this.$dispatch('error', '换表管理', this.data, error)
        })
      } else {
        this.$dispatch('firstsuccess', 'nohand', null)
      }
    },
    clean () {
      this.$dispatch('clean', this.row)
    }
  }
}
</script>
